#pragma once

#include "lockqueue.h"
#include <string>

enum LogLevel
{
    INFO,
    ERROR,
};

class Logger
{
public:
    static Logger &getInstance();
    void setLogLevel(LogLevel logLevel);
    void log(std::string msg);

private:
    Logger();
    Logger(const Logger &) = delete;
    Logger(const Logger &&) = delete;

    Logger &operator=(const Logger &) = delete;
    Logger &operator=(const Logger &&) = delete;

private:
    int logLevel_;
    LockQueue<std::string> lockQue_;
};

#define LOG_INFO(logmsgformat, ...)                          \
    do                                                       \
    {                                                        \
        Logger &logger = Logger::getInstance();              \
        logger.setLogLevel(INFO);                            \
        char logmsg[1024] = {0};                             \
        snprintf(logmsg, 1024, logmsgformat, ##__VA_ARGS__); \
        logger.log(logmsg);                                  \
    } while (0);

#define LOG_ERR(logmsgformat, ...)                           \
    do                                                       \
    {                                                        \
        Logger &logger = Logger::getInstance();              \
        logger.setLogLevel(ERROR);                           \
        char logmsg[1024] = {0};                             \
        snprintf(logmsg, 1024, logmsgformat, ##__VA_ARGS__); \
        logger.log(logmsg);                                  \
    } while (0);
